package com.kws.merchant.mapper;

import com.kws.merchant.domain.Item;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kws.merchant.domain.vo.PowerStationVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * 报价-项目(Item)表数据库访问层
 *
 * @author yxy
 * @since 2024-10-24 14:46:58
 */

public interface ItemMapper extends BaseMapper<Item> {

    /**
     * 计算表下一个id值
     *
     * @return
     */
    @Select("SELECT MAX(id) + 1 FROM tb_item;")
    Long getNextId();

    @Select(
            "<script>" +
                    "SELECT " +
                    " a.id as item_id, " +
                    " a.item_name, " +
                    " a.item_no, " +
                    " b.site_url as item_address, " +
                    " b.serve_type as item_type, " +
                    " c.user_name, " +
                    " c.phonenumber as phone_number  " +
                    " FROM " +
                    " tb_item AS a " +
                    " LEFT JOIN tb_online_inquiry AS b ON a.id = b.item_id " +
                    " LEFT JOIN sys_user AS c ON a.user_id = c.user_id  " +
                    " WHERE " +
                    " a.user_id = ${userId} " +
                    " <if test='itemName!=null and itemName!=\"\"'>  AND .item_name '${itemName}'  </if>  " +
                    " limit #{page},#{size}" +
                    "</script>")
    List<PowerStationVo> getPowerStationList(@Param("itemName") String itemName,
                                             @Param("userId") Long userId,
                                             @Param("page") Integer page,
                                             @Param("size") Integer size);
}
